( function(){

    let btn = document.querySelector( 'button' );
    let nameInput = document.querySelector( '[name=name]' );
    let locInput = document.querySelector( '[name=location]' );
    let tip = document.querySelector( '.tip' );

    let fn = e => {
        let name = nameInput.value ;
        let location = locInput.value ;
        
        if( !name || !location ){
            e.preventDefault();
            tip.innerHTML = '部门名称和地区都不能为空' ;
        }
        /*
        if( name && location ) {
            // 啥也不做，按钮的默认行为会执行(即提交表单)
        } else {
            e.preventDefault();
            tip.innerHTML = '部门名称和地区都不能为空' ;
        }*/
    }

    btn.addEventListener( 'click' , fn , false );

} )();